package com.sanhuo.idms.controller;

import com.sanhuo.idms.bo.ClasRemoveBO;
import com.sanhuo.idms.bo.ClasSaveBO;
import com.sanhuo.idms.entity.Clas;
import com.sanhuo.idms.service.ClasService;
import com.sanhuo.idms.service.CollegeService;
import com.sanhuo.idms.vo.ClasVo;
import com.sanhuo.idms.vo.CollegeVO;
import com.sanhuo.security.uitls.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("clas")
@RestController
public class ClasController {
    @Autowired
    private ClasService clasService;
    @Autowired
    private CollegeService collegeService;

    @RequestMapping("detail")
    public Clas findById(String id) {
        return clasService.findById(id);
    }

    @RequestMapping("save")
    public void save(ClasSaveBO bo) throws IllegalAccessException {
        clasService.save(UserHolder.user(), bo);
    }

    @RequestMapping("remove")
    public void remove(ClasRemoveBO bo) {
        clasService.remove(bo);
    }

    @RequestMapping("")
    public List<CollegeVO> findAll(String collegeId) {
//        SimpleDateFormat sdf = new SimpleDateFormat("mm:ss");
//        System.out.println(sdf.format(new Date()));
        List<String> grades = clasService.findGrade();
        List<CollegeVO> result = new ArrayList<>();
        for (String grade : grades) {
            CollegeVO college = new CollegeVO();
            college.setCollegeId(collegeId);
            college.setClasGrade(grade);
            List<ClasVo> clas = clasService.findClas(collegeId, grade);
            college.setClas(clas);
            result.add(college);
        }
//        System.out.println(sdf.format(new Date()));
        return result;
    }
//    @RequestMapping("save")
//    public void save() {
//        List<College> colleges = collegeService.findAll();
//
//        for (College college : colleges) {
//            if (Integer.parseInt(college.getId()) > 10) {
//                int grade = 15;
//                for (int i = 0; i < 4; i++) {
//                    for (int j = 0; j < 15; j++) {
//                        String clasNum = Integer.toString(j + 1);
//                        if (j + 1 < 10) {
//                            clasNum = "0" + clasNum;
//                        }
//                        Clas clas = new Clas();
//                        String id = StringUtil.UUID();
//                        clas.setId(id);
//                        clas.setClasGrade(Integer.toString(grade));
//                        clas.setClasNum(clasNum);
//                        clas.setCollegeId(college.getId());
//                        clas.creatorAndUpdatorInfo(UserHolder.user());
//                        clasService.save(clas);
//                    }
//                    grade++;
//                }
//            }
//        }
//    }
}
